package advance.x000.acw_998;


import java.util.*;

/**
 * https://www.acwing.com/problem/content/1000/
 * dp 位运算 贪心
 */
public class Main {
    static class Rule {
        String rule;
        Integer value;

        public Rule(String rule, Integer value) {
            this.rule = rule;
            this.value = value;
        }
    }


    List<Rule> rules = new ArrayList<>();

    // 注意依次经过
    public static void main(String[] args) {
        Main solution = new Main();
        Scanner scanner = new Scanner(System.in);
        // 读取参数 n扇门 m 攻击数范围
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        // 读取，存储经过的防御规则

        for (int i = 0; i < n; i++) {
            Rule rule = new Rule(scanner.next(), scanner.nextInt());
            solution.rules.add(rule);
        }

        int val = 0;
        int ans = 0;
        // 0<k<30
        for (int bit = 29; bit >= 0; bit--) {
            // 传递的是bit位 从29位开始往下一位逐次尝试
            int res0 = solution.calc(bit, 0);
            int res1 = solution.calc(bit, 1);
            // 假如经过运算 且 没有超过m bit位置1
            if ( (val + (1 << bit)) <= m && res1 > res0 ) {
                val |= 1 << bit;
                ans |= res1 << bit;
                // 答案的该bit位也置1
            } else {
                // bit位0的答案，没有加bit位不会超m，状态合法的
                ans |= res0 << bit;
            }
        }
        System.out.println(ans);
    }

    public int calc(int bit, Integer now) {
        for (Rule rule : this.rules) {
            String opt = rule.rule;
            Integer value = rule.value;
            int x = (value >> bit) & 1;
            if (opt.equals("AND")) {
                now &= x;
            } else if (opt.equals("OR")) {
                now |= x;
            } else {
                now ^= x;
            }
        }
        return now;
    }


}
